package com.jxdinfo.hussar.activitidemo.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class UUIDtools {
	/**
	 * 以UUID的方式获取主键获取主键
	 * @return
	 */
	public static synchronized String getUuid(){
		String uuid = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
		return uuid;
	}
	/**
	 * 查询通配符转义
	 * @param str
	 * @return
	 */
	public static String encodeQuery(String str){
		str = str.replace("%", "\\%");
		str = str.replace("_", "\\_");
		return str;
	}
	
	public static String dateToString(Date date,String fmt){
        SimpleDateFormat dateFormat=new SimpleDateFormat(fmt);
        String now = dateFormat.format(date);
        return now;
    }
	
	public static String formateTime(String temp){
		Pattern pattern = Pattern.compile("[0-9]*");   
		Matcher isNum = pattern.matcher(temp); 
		int hour = 0;
		int minute = 0;
		if(isNum.matches() ){  
			 hour = Integer.parseInt(temp)/60;
			 minute = Integer.parseInt(temp)%60;   
		   }else{
			  hour = (int) (Float.parseFloat(temp)/60);
			  minute =(int)(Float.parseFloat(temp)%60);  
		   }
		
		String og = "";
		if(hour!=0){
			og = hour+"小时"+minute+"分";
		}else{
			og = minute+"分";
		}
		return og;
	}
	
}
